package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Recruitplan;
import cn.wolfcode.crm.qo.EmployeeInfoQueryObject;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.RecruitPlanQueryObject;
import cn.wolfcode.crm.service.IRecruitPlanService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("recruitPlan")
@Controller
public class RecruitplanController {
    @Autowired
    private IRecruitPlanService recruitPlanService;

    @RequestMapping("view")
    public String list() {
        return "/recruitPlan/recruitPlan";
    }

    //异步加载数据
    @RequestMapping("query")
    @ResponseBody
    public Object list(@ModelAttribute("qo") RecruitPlanQueryObject qo, Model model) {
        //将数据转换成json格式
        PageResult result = recruitPlanService.query(qo);

        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        try {
            recruitPlanService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("");
        }
        return JSONResult.success("删除成功!");
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Recruitplan recruitPlan) {
        try {
            if (recruitPlan.getId() == null)
                recruitPlanService.insert(recruitPlan);
            else
                recruitPlanService.updateByPrimaryKey(recruitPlan);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("保存失败!");
        }
        return JSONResult.success("保存成功!");
    }
    @RequestMapping("changeState")
    @ResponseBody
    public JSONResult changeState(Long id)
    {
        try
        {
            recruitPlanService.changeState(id);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return JSONResult.mark("操作失败!");
        }
        return JSONResult.success("操作成功!");
    }
}
